import mongoose from 'mongoose';
import Kutils from '../modules/Kutils';

const kutil = new Kutils();
const TABLE_NAME = 'device_profile';

function createdTime() {
    return +new Date();
}

function formatDate() {
    return kutil.dateFormat(new Date());
}

const schema = new mongoose.Schema({
    createdTime: { type: Number, default: createdTime },
    createdDate: { type: String, default: formatDate },
    updatedDate: { type: String, default: formatDate },
    sys: String,
    wid: Number,
    uid: Number,
    serialId: String,
    deviceId: String,
    ver: { type: String, default: '1.0.0' },
    env: {},
    config: {},
    state: {
        openTime: { type: Number, default: createdTime },
        closeTime: { type: Number, default: createdTime },
        device: { type: String, default: 'close' },
        km: { type: String, default: 'close' },
        serverIp: String,
        clientIp: String,
    },
    cat: String,        // 系统 xp/win7
    remark: String,
}, { versionKey: false });

export const model = mongoose.model(TABLE_NAME, schema);
